package com.bjtu.literatureclient.feign;


import com.bjtu.literatureclient.api.vo.request.SyncJournalRequest;
import com.bjtu.literatureclient.base.result.Result;
import feign.hystrix.FallbackFactory;
import org.springframework.cloud.netflix.feign.FeignClient;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

/**
 * @author caiyuli
 * @date 2020/4/25 5:33 下午
 */

@FeignClient(value = "transactionclient", fallbackFactory = JournalFeignService.HystrixClientFallbackFactory.class)
public interface JournalFeignService {

    @RequestMapping(value = "/journal/sync-add", method = RequestMethod.POST, produces = MediaType.APPLICATION_JSON_VALUE)
    Result syncJournal(SyncJournalRequest request);



    @Component
    static class HystrixClientFallbackFactory implements FallbackFactory<JournalFeignService> {

        @Override
        public JournalFeignService create(Throwable throwable) {
            return new JournalFeignService() {
                @Override
                public Result syncJournal(SyncJournalRequest request) {
                    return Result.fail("与服务端通信失败");
                }
            };
        }
    }


}
